home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / 3DMAZE / MAZE.C < prev    next >
C/C++ Source or Header  |  1991-02-16  |  6KB  |  261 lines

  1. /* --- This source is for Lightspeed C 3.0 or greater --- */
  2. /* InitTheMenus  initializes the menus */
  3. /*     About       Modal Dialog */
  4. /*     P_D_Maze       Window */
  5. /* HandleTheMenus   Handle the menu selection */
  6. /* Resource file to use is  Maze.RSRC  */
  7. /* RMaker file to use is Maze.R   */
  8. /* Maze.c      Main program   */
  9. /* MacTraps        use this LSC library from the    Mac Libraries    folder */
  10. /* strings         use this LSC library from the    Libraries    folder */
  11.  
  12.  
  13. /* ==============================
  14.  
  15. Program name:  Maze.c
  16. Function:  This is the main module for this program. 
  17. History: 2/15/91 Original by Prototyper. 
  18.  
  19. ================================= */
  20.  
  21.     /* *********************************** */
  22.     /* These are the other includes for general routines */
  23.  
  24. #include "Strings.h"
  25.     extern char * strcpy(Str255 *, char *);
  26.  
  27.     /* *********************************** */
  28.  
  29. #define      TRUE   1
  30. #define      FALSE  0
  31. #define      NIL    0
  32.  
  33.     /* *********************************** */
  34.  
  35. /* External routines that are called */
  36.  
  37. extern  void InitMyMenus(void);
  38. extern  void HandleMenu(char *doneFlag, short   theMenu, short   theItem, TEHandle *theInput);
  39.  
  40. #include "About.h"
  41. #include "P_D_Maze.h"
  42. /* ====================================== */
  43. /* ====================================== */
  44. void main(void);
  45. /* ====================================== */
  46.  
  47.  
  48. void main()
  49. {
  50.     char          doneFlag;
  51.     char          Is_A_Dialog;
  52.     char          stillInGoAway;
  53.     char          ch;
  54.     short        code;
  55.     short        theMenu,theItem;
  56.     short        chCode;
  57.     long         mResult;
  58.     WindowPtr    whichWindow;
  59.     EventRecord  myEvent;
  60.     TEHandle     theInput;
  61.     Rect         tempRect,OldRect;
  62.     Point         myPt;
  63.     GrafPtr       SavePort;
  64.     
  65.  
  66.  
  67.  
  68.     InitGraf(&thePort);
  69.     InitFonts();
  70.     FlushEvents(everyEvent,0);
  71.     InitWindows();
  72.     InitMenus();
  73.     TEInit();
  74.     InitDialogs(NIL);
  75.     InitCursor();
  76.  
  77.     doneFlag = FALSE;
  78.  
  79.     InitMyMenus();
  80.     theInput = NIL;
  81.     Init_P_D_Maze();
  82.     Open_P_D_Maze(&theInput);
  83.  
  84.     do
  85.     {
  86.         if (theInput != NIL) 
  87.             TEIdle(theInput);
  88.         SystemTask();
  89.  
  90.  
  91.         if (GetNextEvent(everyEvent, &myEvent))    
  92.         {
  93.             code = FindWindow(myEvent.where, &whichWindow);    
  94.  
  95.  
  96.             switch (myEvent.what)
  97.             {
  98.                 case mouseDown:
  99.                     if (code == inMenuBar)
  100.                     {
  101.                         mResult = MenuSelect(myEvent.where);
  102.                         theMenu = HiWord(mResult);
  103.                         theItem = LoWord(mResult);
  104.                         HandleMenu(&doneFlag,theMenu,theItem,&theInput);
  105.                     }
  106.  
  107.                      if ((code == inDrag)&&(whichWindow != NIL))
  108.                     {
  109.                          tempRect = screenBits.bounds;
  110.                          SetRect(&tempRect, tempRect.left + 10, tempRect.top + 25, tempRect.right - 10, tempRect.bottom - 10);
  111.                          DragWindow(whichWindow, myEvent.where, &tempRect);
  112.                     }
  113.  
  114.                     if (code == inGrow)
  115.                     {
  116.                         SetPort(whichWindow);
  117.  
  118.                         myPt = myEvent.where;
  119.                         GlobalToLocal(&myPt);
  120.  
  121.                         OldRect.left = whichWindow->portRect.left;
  122.                         OldRect.right = whichWindow->portRect.right;
  123.                         OldRect.top = whichWindow->portRect.top;
  124.                         OldRect.bottom = whichWindow->portRect.bottom;
  125.  
  126.                         SetRect(&tempRect,15,15,(screenBits.bounds.right - screenBits.bounds.left), (screenBits.bounds.bottom - screenBits.bounds.top) - 20);
  127.                         mResult = GrowWindow(whichWindow, myEvent.where, &tempRect);
  128.                         SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), TRUE);
  129.  
  130.  
  131.                         SetPort(whichWindow);
  132.  
  133.                         SetRect(&tempRect, 0, myPt.v - 15, myPt.h + 15, myPt.v + 15); 
  134.                         EraseRect(&tempRect);
  135.                         InvalRect(&tempRect);
  136.                         SetRect(&tempRect, myPt.h - 15, 0, myPt.h + 15, myPt.v + 15);  
  137.                         EraseRect(&tempRect);
  138.                         InvalRect(&tempRect);
  139.                         DrawGrowIcon(whichWindow);
  140.                     }
  141.  
  142.                     if (code == inGoAway)
  143.                     {
  144.                         stillInGoAway = TrackGoAway(whichWindow,myEvent.where);
  145.                         if (stillInGoAway == TRUE)
  146.                         {
  147.                             switch (GetWRefCon(whichWindow)) 
  148.                             { 
  149.                                 case 1: 
  150.                                     Close_P_D_Maze(whichWindow,&theInput);
  151.                                     break;
  152.                             }
  153.                         }
  154.                     }
  155.  
  156.                     if (code == inContent)
  157.                     {
  158.                         if (whichWindow != FrontWindow()) 
  159.                         {
  160.                             SelectWindow(whichWindow);
  161.                         }
  162.                         else
  163.                         {
  164.                             SetPort(whichWindow);
  165.                             switch (GetWRefCon(whichWindow)) 
  166.                             { 
  167.                                 case 1: 
  168.                                     Do_P_D_Maze (&myEvent,&theInput );
  169.                                     break;
  170.                             }
  171.                         }
  172.                     }
  173.  
  174.                     if (code == inSysWindow)
  175.                     {
  176.                         SystemClick(&myEvent, whichWindow);
  177.                     }
  178.  
  179.                     if ((code == inZoomIn) || (code == inZoomOut))
  180.                     {
  181.                         if (whichWindow != NIL)
  182.                         {
  183.                             SetPort(whichWindow);
  184.  
  185.                             myPt = myEvent.where;
  186.                             GlobalToLocal(&myPt);
  187.  
  188.                             if (TrackBox(whichWindow, myPt, code) == TRUE)
  189.                             {
  190.                                 ZoomWindow(whichWindow, code, TRUE);
  191.                                 SetRect(&tempRect, 0, 0, 32000, 32000);
  192.                                 EraseRect(&tempRect);
  193.                                 InvalRect(&tempRect);
  194.  
  195.                             }
  196.                         }
  197.                     }
  198.  
  199.                     break;
  200.  
  201.                 case keyDown: 
  202.                 case autoKey: 
  203.                     ch = myEvent.message &  charCodeMask;
  204.                     mResult = MenuKey(ch);
  205.                     theMenu = HiWord(mResult);
  206.                     theItem = LoWord(mResult);
  207.                     if (theMenu != 0) 
  208.                         HandleMenu(&doneFlag, theMenu, theItem, &theInput); 
  209.                     break;
  210.  
  211.                 case updateEvt:
  212.                     whichWindow = (WindowPtr)myEvent.message;
  213.                     GetPort(&SavePort);
  214.                     BeginUpdate(whichWindow);
  215.                     SetPort(whichWindow);
  216.                     switch (GetWRefCon(whichWindow)) 
  217.                     { 
  218.                         case 1: 
  219.                             UpDate_P_D_Maze(whichWindow);
  220.                             break;
  221.                     }
  222.                     EndUpdate(whichWindow);
  223.                     SetPort(SavePort);
  224.                     break;
  225.  
  226.                 case diskEvt:
  227.                     if (HiWord(myEvent.message) != 0) 
  228.                     {
  229.                         myEvent.where.h = ((screenBits.bounds.right - screenBits.bounds.left) / 2) - (304 / 2);
  230.                         myEvent.where.v = ((screenBits.bounds.bottom - screenBits.bounds.top) / 3) - (104 / 2);
  231.                         InitCursor();
  232.                         theItem = DIBadMount(myEvent.where, myEvent.message);
  233.                     }
  234.                     break;
  235.  
  236.                 case app1Evt:
  237.                     if (((HiWord(myEvent.message) == 1) && (LoWord(myEvent.message)) ==1))
  238.                         Open_P_D_Maze(&theInput);
  239.                     if (((HiWord(myEvent.message) == 2) && (LoWord(myEvent.message)) ==1))
  240.                         Close_P_D_Maze((WindowPtr)-1,&theInput);
  241.                     break;
  242.  
  243.                 case activateEvt:
  244.                     if ((whichWindow != NIL) && (myEvent.modifiers & activeFlag))
  245.                     { 
  246.                         SelectWindow(whichWindow);
  247.                     }
  248.                     break;
  249.  
  250.  
  251.                 default:
  252.                     break;
  253.  
  254.             }
  255.  
  256.         }
  257.     }
  258.     while (doneFlag ==  FALSE);
  259.  
  260. }
  261.